package com.cloud.phone.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @auth: njb
 * @date: 2024/6/12 18:21
 * @desc: 描述
 */
public class ThreadPoolManager {
    private ExecutorService executorService;

    private static ThreadPoolManager instance;

    private ThreadPoolManager() {
        // 创建一个固定大小的线程池
        executorService = Executors.newFixedThreadPool(5);
    }

    public static synchronized ThreadPoolManager getInstance() {
        if (instance == null) {
            instance = new ThreadPoolManager();
        }
        return instance;
    }

    public void executeTask(Runnable task) {
        if (executorService != null) {
            executorService.execute(task);
        }
    }

    public void shutdown() {
        if (executorService != null) {
            executorService.shutdown();
            executorService = null;
        }
    }
}
